package com.example.user.controller;


import com.example.user.common.Result;
import com.example.user.entity.CommunityActivity;
import com.example.user.entity.Favorite;
import com.example.user.service.ActivityDetailInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@CrossOrigin(origins = "http://localhost:8080")
public class ActivityDetailInfoController {

    @Autowired
    private ActivityDetailInfoService activityDetailInfoService;

    @GetMapping("/selectDetail")
    public Result<PageInfo> selectDetail(@RequestParam Integer pageNumber,@RequestParam Integer pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
      List<CommunityActivity> communityActivityList= activityDetailInfoService.selectDetail();
      PageInfo<CommunityActivity> pageInfo = new PageInfo<>(communityActivityList);
      return Result.success(pageInfo);
    }


    @GetMapping("/selectActivityById")
    public Result<PageInfo> selectActivityById(@RequestParam Integer activityId) {
        PageHelper.startPage(1, 1);
      List< CommunityActivity > communityActivity=activityDetailInfoService.selectActivityById(activityId);
       return Result.success(new PageInfo(communityActivity));

    }


    /**
     * 收藏接口
     */

    @PostMapping("/addFavorite")
    public Result addFavorite(@RequestBody Favorite favorite)  {

       Result result= activityDetailInfoService.addFavorite(favorite);
       return result;
    }

    @GetMapping("/selectFavorite")

    public Result selectFavorite(@RequestParam Integer activityId) {
       Result result= activityDetailInfoService.selectFavoriteById(activityId);
       return result;
    }

}
